<%--
  Created by IntelliJ IDEA.
  User: 86150
  Date: 2021/10/26
  Time: 18:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>业绩查询</title>
    <link type="text/css" rel="stylesheet" href="fontsawesome/css/font-awesome.css"/>
    <link type="text/css" rel="stylesheet" href="css/datepicker.css"/>
    <link type="text/css" rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="main_box">
    <h2><span></span>业绩查询</h2>
    <form action="${pageContext.request.contextPath}/Af1" method="post">
        <div class="search_box clearfix">
            <label class="f_left">开始日期：</label>
            <div class="date_box">
                <input type="text" name="regtime" id="start_date" readonly/>
                <i class="fa fa-calendar"></i>
            </div>
            <label class="f_left">结束日期：</label>
            <div class="date_box">
                <input type="text" name="regtime1" id="end_date" readonly/>
                <i class="fa fa-calendar"></i>
            </div>
            <input type="submit" value="搜索" class="btn blue_btn"/>
<%--            <input type="button" value="导出门店业绩" class="btn btn_info">--%>
        </div>
    </form>
    <div class="cont_box" style="border-top:1px dashed #ddd;">
        <p class="business_tit">营业额详情表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table business_table" id="table_box">
            <input type="submit"  onclick="exportExcel('table_box')" value="导出营业额详情表" class="btn btn_info"/>
            <tbody>
                <tr>
                    <td>充值收入</td>
                    <td>${sum}</td>
                </tr>
                <tr>
                    <td>非会员收入</td>
                    <td>${cmoney}</td>
                </tr>
                <tr>
                    <td>大礼包收入</td>
                    <td>${gifts}</td>
                </tr>
                <tr>
                    <td>营业总额</td>
                    <td>${sunn}</td>
                </tr>

            </tbody>
        </table>
        <p class="business_tit">营业额说明</p>
        <ul class="business_info">
            <li>营业总额 = 充值收入 + 非会员收入 + 大礼包收入</li>
            <li>充值收入（<span>5800</span>） = 储值卡收入（<span>3800</span>） + 年卡收入（<span>2000</span>）</li>
            <li>储值卡消费总额：<span>2999</span> 元</li>
            <li>年卡消费总次数：<span>0</span> 次</li>
            <li>年卡开卡总数：<span>1</span> 张</li>
        </ul>
        <p class="business_tit">非会员收入详情表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table" id="table_box1">
            <input type="submit"  onclick="exportExcel('table_box1')" value="导出非会员收入详情表" class="btn btn_info"/>
            <thead>
            <tr>
                <th class="slash">
                    <div class="slash_line">

                    </div>
                </th>
            <c:forEach items="${bill}" var="bill">
                <th>${bill.zhifu}</th>
            </c:forEach>
                <th>总计</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>消费金额</td>
                <c:forEach items="${bill}" var="bill">
                <td>${bill.moneysum}</td>
                </c:forEach>
                <td>${cmoney}</td>
            </tr>
            <tr>
                <td>消费次数</td>
<c:forEach items="${bill}" var="bill">
                <td>${bill.zhifucount}</td>
</c:forEach>
                <td>${bills}</td>

                <td hidden></td>
            </tr>
            </tbody>
        </table>
        <p class="business_tit">储值卡详情表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table business_table" id="table_box2">
            <input type="submit"  onclick="exportExcel('table_box2')" value="导出储值卡详情表" class="btn btn_info"/>
            <tbody>
<c:forEach items="${Pet_cardc}" var="Pet_cardc">
            <tr>
                <td>${Pet_cardc.kind}</td>
                <td>${Pet_cardc.c}</td>
            </tr>
</c:forEach>
            <tr>
                <td>总计</td>
                <td>${card}</td>
            </tr>

            </tbody>
        </table>
    </div>
</div>
<!--javascript include-->
<script src="js/jquery-2.2.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/other.js"></script>
<script>
    $(function(){
        var tdW = $(".slash").width(),
            tdH = $(".slash").height();
        $(".slash_line").css({"border-left-width":parseInt(tdW),"border-top-width":parseInt(tdH)});
    });

    var idTmr;
    //获取当前浏览器类型
    function getExplorer() {
        var explorer = window.navigator.userAgent ;
        //ie
        if (explorer.indexOf("MSIE") >= 0) {
            return 'ie';
        }
        //firefox
        else if (explorer.indexOf("Firefox") >= 0) {
            return 'Firefox';
        }
        //Chrome
        else if(explorer.indexOf("Chrome") >= 0){
            return 'Chrome';
        }
        //Opera
        else if(explorer.indexOf("Opera") >= 0){
            return 'Opera';
        }
        //Safari
        else if(explorer.indexOf("Safari") >= 0){
            return 'Safari';
        }
    }

    //获取到类型需要判断当前浏览器需要调用的方法，目前项目中火狐，谷歌，360没有问题
    //win10自带的IE无法导出
    function exportExcel(tableid) {
        if(getExplorer()=='ie')
        {
            var curTbl = document.getElementById(tableid);
            var oXL = new ActiveXObject("Excel.Application");
            var oWB = oXL.Workbooks.Add();
            var xlsheet = oWB.Worksheets(1);
            var sel = document.body.createTextRange();
            sel.moveToElementText(curTbl);
            sel.select();
            sel.execCommand("Copy");
            xlsheet.Paste();
            oXL.Visible = true;

            try {
                var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
            } catch (e) {
                print("Nested catch caught " + e);
            } finally {
                oWB.SaveAs(fname);
                oWB.Close(savechanges = false);
                oXL.Quit();
                oXL = null;
                idTmr = window.setInterval("Cleanup();", 1);
            }

        }
        else
        {
            tableToExcel(tableid)
        }
    }
    function Cleanup() {
        window.clearInterval(idTmr);
        CollectGarbage();
    }

    //判断浏览器后调用的方法，把table的id传入即可
    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html><head><meta charset="UTF-8"></head><body><table>{table}</table></body></html>',
            base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
            format = function(s, c) {
                return s.replace(/{(\w+)}/g,
                    function(m, p) { return c[p]; }) }
        return function(table, name) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
            window.location.href = uri + base64(format(template, ctx))
        }
    })()
</script>
</body>
</html>
